// JavaScript Document

// This script draws a google map with the home base and other starting points.

/*
	Copyright 2011 Tobias Heinzer + Peter Affentranger

	This file is part of the website flugservice.ch.

    The website flugservice.ch is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The website flugservice.ch is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with the website flugservice.ch.  If not, see <http://www.gnu.org/licenses/>.
*/

      var map;
	  
	  function initialize() {
        var mapDiv = document.getElementById('map-canvas');
		
		// Define map styles
		var mapStyles = [
			{featureType: "road",
    			stylers: [
      				{ visibility: "off" }
    			]
  			},
			{featureType: "administrative.province",
    			stylers: [
      				{ visibility: "off" }
    			]
  			},
			{featureType: "landscape.natural",
    			stylers: [
      				{ visibility: "off" }
    			]
  			}];
        
		// Define map
		map = new google.maps.Map(mapDiv, {
          mapTypeId: google.maps.MapTypeId.TERRAIN,
		  styles: mapStyles
        });
		
		// Fit map with markers to available space
		var sw = new google.maps.LatLng(46.002596, 6.112347);
		var ne = new google.maps.LatLng(47.598640, 9.883361);
		var bounds = new google.maps.LatLngBounds(sw, ne);
		map.fitBounds(bounds);

		google.maps.event.addListenerOnce(map, 'tilesloaded', addMarkers);
      }
      
	  function addMarkers () {
		  var airfields = [
				new google.maps.LatLng(47.204703, 8.867040),
				new google.maps.LatLng(47.181663, 7.412424),
				new google.maps.LatLng(46.911930, 7.501774),
				new google.maps.LatLng(47.598640, 7.529583),
				new google.maps.LatLng(47.443676, 8.231463),
				new google.maps.LatLng(47.453050, 8.560710),
				new google.maps.LatLng(47.485425, 9.559822),
				new google.maps.LatLng(46.237090, 6.112347),
				new google.maps.LatLng(46.220257, 7.329812),
				new google.maps.LatLng(46.002596, 8.907080),	
				new google.maps.LatLng(46.532502, 9.883361)];
		  
		  var airfieldnames = [
				"Wangen-Lachen",
				"Grenchen",
				"Bern-Belp",
				"Basel EuroAirport",
				"Birrfeld",
				"Zürich-Kloten",
				"Sankt Gallen-Altenrhein",
				"Genf",
				"Sitten",
				"Lugano-Agno",
				"Samedan"];
		  
		  // Add marker for every starting point
		  for (i = 0; i < airfields.length; i++) {
			  var latLng = airfields[i];

			// Blue marker for home base
			if (i == 0) {
				// Custom marker code created with Google Map Custom Marker Maker
				// http://www.powerhut.co.uk/googlemaps/custom_markers.php
				var image = new google.maps.MarkerImage(
				  '../images/gmap_marker_blue.png',
				  new google.maps.Size(32,32),
				  new google.maps.Point(0,0),
				  new google.maps.Point(16,32)
				);

				var shadow = new google.maps.MarkerImage(
				  '../images/gmap_marker_blue_shadow.png',
				  new google.maps.Size(52,32),
				  new google.maps.Point(0,0),
				  new google.maps.Point(16,32)
				);

				var shape = {
				  coord: [19,0,20,1,21,2,22,3,23,4,24,5,24,6,24,7,24,8,24,9,24,10,24,11,24,12,23,13,23,14,22,15,21,16,20,17,20,18,19,19,19,20,18,21,18,22,17,23,17,24,17,25,17,26,16,27,16,28,16,29,16,30,16,31,14,31,14,30,14,29,14,28,14,27,14,26,13,25,13,24,13,23,12,22,12,21,12,20,11,19,10,18,10,17,9,16,8,15,7,14,7,13,6,12,6,11,6,10,6,9,6,8,6,7,6,6,7,5,7,4,8,3,9,2,10,1,11,0,19,0],
				  type: 'poly'
				};

				var marker = new google.maps.Marker({
				  icon: image,
				  shadow: shadow,
				  shape: shape,
				  position: latLng,
				  title: airfieldnames[i],
            	  map: map
				});
			}
			// Default marker for other starting points
			else {
			  var marker = new google.maps.Marker({
				position: latLng,
				title: airfieldnames[i],
            	map: map
          	  });
			}
		  }
	  }

      google.maps.event.addDomListener(window, 'load', initialize);
